package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.media.dto.SensitiveDto;
import com.heima.media.entity.WmSensitive;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmSensitiveService;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 敏感词信息表 前端控制器
 * </p>
 *
 * @author syl
 * @since 2023-04-21
 */
@RestController
@RequestMapping("/api/v1/sensitive")
@Api(tags = "敏感词信息表接口")
@CrossOrigin
public class WmSensitiveController{

    @Autowired
    private IWmSensitiveService wmSensitiveService;
    @PostMapping("/list")
    @ApiOperation("根据敏感词信息表")
    public ResponseResult listByName(@RequestBody SensitiveDto dto){
        return wmSensitiveService.listByName(dto);
    }

    //新增操作
    @PostMapping()
    @ApiOperation("新增敏感词")
    public ResponseResult saveSensitiveWord(@RequestBody WmSensitive wmSensitive){
        return wmSensitiveService. saveSensitiveWord(wmSensitive);

    }

    //修改操作
    @PutMapping
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        LambdaQueryWrapper<WmSensitive> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WmSensitive::getSensitives,wmSensitive.getSensitives());
        if(wmSensitiveService.count(lambdaQueryWrapper)>0){
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_EXIST);
        }
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.updateById(wmSensitive);
        return ResponseResult.okResult();
    }



    //删除操作
    @DeleteMapping("/{id}")
    @ApiOperation("删除敏感词")
    public ResponseResult deleteSensitiveWord(@PathVariable Integer id ){
        return wmSensitiveService.deleteSensitiveWord(id);
    }

    //查询操作(查询全部)

    //查询操作(根据id查询)



}
